package com.wubo.sec.config;

import java.util.ResourceBundle;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class LangUtil {
	private static Log log = LogFactory.getLog(LangUtil.class);
	
	private static ResourceBundle rb;
	private final static String LANG_BASE_NAME = "locale/lang";
	static {
		rb = ResourceBundle.getBundle(LANG_BASE_NAME); 
	}
	
	public static String get(String key, Object... params){
		try{
			
			String value =  rb.getString(key);
			if(params != null){
				for(int i=0; i<params.length; i++){
					value = value.replaceAll("\\{"+i+"\\}", params[i].toString());
				}
			}
			return value;
		}catch(Exception e){
			log.warn("Can't find resource for bundle key:"+key+"!");
			return key;
		}
	}
	
	public static void main(String[] args) throws Exception {
		java.net.URL url =LangUtil.class.getClassLoader().getResource("locale/lang_zh.txt");
		System.out.println("转换中文 -> UTF-8");
		Runtime.getRuntime().exec("native2ascii -encoding utf-8 "+url.getPath()+" lang_zh_CN.properties");
		System.out.println("转换成功！");
	}
}
